<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="https://www.baidu.com/">
        <input type="submit" value="免费注册">
        <a href="https://www.baidu.com/">百度</a>
    </form>
    <script>
        // 获取父元素
        const form = document.querySelector("form")
        // 添加提交事件
        form.addEventListener("submit", function (e) {
            // 阻止跳转链接默认行为
            e.preventDefault()
        })

        document.querySelector("a").addEventListener("click", function (e) {
            // 阻止跳转链接默认行为

            e.preventDefault()
        })
    </script>
</body>

</html>